package com.beidasoft.web.model.statisticalAnalysis;

import java.math.BigDecimal;
import java.util.Comparator;

/**
 * 全市案件金额统计  -- 排序操作
 * Created by Ronin on 2016/1/5.
 */
public class CasesMoneySummarySort implements Comparator {
    //传一个排序标识
    private String sort;
    public CasesMoneySummarySort(String sort){
        this.sort = sort;
    }

    @Override
    public int compare(Object o1, Object o2) {
        CasesMoneySummary caseAmount1 = (CasesMoneySummary)o1;
        CasesMoneySummary caseAmount2 = (CasesMoneySummary)o2;
        if (sort.equals("01")){
            //按部门降序
            return sortDownByDepartment(caseAmount1, caseAmount2);
        }else if (sort.equals("02")){
            //按部门升序
            return sortUpByDepartment(caseAmount1, caseAmount2);
        }else if (sort.equals("21")){
            //按总案件量升序
            return sortUpByCaseCount(caseAmount1, caseAmount2);
        }else{
            //按总案件量降序
            return sortDownByCaseCount(caseAmount1, caseAmount2);
        }
    }

    //升序
    private int sortUpByDepartment(CasesMoneySummary o1, CasesMoneySummary o2) {
        String val1 = o1.getBmbh();
        String val2 = o2.getBmbh();

        if (val1.compareTo(val2) < 0) {
            return -1;
        } else if (val1.compareTo(val2) > 0) {
            return 1;
        } else {
            return 0;
        }
    }
    private int sortUpByCaseCount(CasesMoneySummary o1, CasesMoneySummary o2) {
        BigDecimal val1 = o1.getCaseCount();
        BigDecimal val2 = o2.getCaseCount();

        if (val1.compareTo(val2) < 0) {
            return -1;
        } else if (val1.compareTo(val2) > 0) {
            return 1;
        } else {
            return 0;
        }
    }
    //降序
    private int sortDownByDepartment(CasesMoneySummary o1, CasesMoneySummary o2) {
        String val1 = o1.getBmbh();
        String val2 = o2.getBmbh();

        if (val1.compareTo(val2) > 0) {
            return -1;
        } else if (val1.compareTo(val2) < 0) {
            return 1;
        } else {
            return 0;
        }
    }
    private int sortDownByCaseCount(CasesMoneySummary o1, CasesMoneySummary o2) {
        BigDecimal val1 = o1.getCaseCount();
        BigDecimal val2 = o2.getCaseCount();
        if (val1.compareTo(val2) > 0) {
            return -1;
        } else if (val1.compareTo(val2) < 0) {
            return 1;
        } else {
            return 0;
        }
    }
}
